package org.jing.ext.ftp;

import org.jing.core.lang.itf.JEnum;

/**
 * Description: Ftp文件类型. <br>
 *
 * @author bks <br>
 * @since 2021-03-31 <br>
 */
public enum FtpFileType implements JEnum<String> {
    BINARY(2, "Binary"), ASCII(0, "Ascii");

    private int fileType;

    private String fileTypeName;

    FtpFileType(int fileType, String fileTypeName) {
        this.fileType = fileType;
        this.fileTypeName = fileTypeName;
    }

    public int getFileType() {
        return fileType;
    }

    public String getFileTypeName() {
        return fileTypeName;
    }

    public static FtpFileType get(int fileType) {
        for (FtpFileType ftpFileType : values()) {
            if (ftpFileType.fileType == fileType) {
                return ftpFileType;
            }
        }
        return null;
    }

    @Override public boolean equalsByType(Object... objects) {
        Object input = objects[0];
        if (input instanceof Integer) {
            return  ((int) input == fileType);
        }
        else if (input instanceof String) {
            return fileTypeName.toUpperCase().charAt(0) == ((String) input).toUpperCase().charAt(0);
        }
        return false;
    }

    @Override public String toString() {
        return fileTypeName.toUpperCase().substring(0, 1);
    }
}